
PM_FUNC_NORM_ATTRIB LocationMenu( Int:iPlayer )
{
	pokemod_funcstart_debug( "LocationMenu" );

	new Int:iMenu = -1;
	new Int:iLocation = PlayerGetInfo( iPlayer, PINFO_LOCATION );
	new String:szLocation[ NAME_LEN ];
	LocationToName( iLocation, szLocation, charsmax(szLocation) );

	if ( PlayerGetInfo( iPlayer, PINFO_TRAVELING ) )
	{
		iMenu = MenuCreate( "Traveling To: %s", LocationToName( PlayerGetInfo( iPlayer, PINFO_TRAVEL_TO ) ) );

		MenuAddItem( iMenu, "MoveStop()", "Stay at %s", szLocation );
	}
	else
	{
		iMenu = MenuCreate( "Location: %s", szLocation );
	}

	MenuAddItem( iMenu, "ViewMap()", "\yView Map" );

	if ( PlayerHasSkill( iPlayer, -1, SKILL_FLY ) != -1 )
		MenuAddItem( iMenu, "Function(Fly)", "\yFly" );

	g_iScriptMenu = iMenu;
	LocationScript( iPlayer, iLocation, "MoveMenu", "" );
	g_iScriptMenu = -1;

	MenuExit( iPlayer, iMenu, .bExitOption = true );
	MenuDisplay( iPlayer, iMenu, MENU_MAIN );

	pokemod_funcend_debug( "LocationMenu" );
}

PM_FUNC_NORM_ATTRIB LocationUpdate( Int:iPlayer )
{
	pokemod_funcstart_debug( "LocationUpdate" );

	if ( PlayerGetInfo( iPlayer, PINFO_TRAVELING ) )
	{
		new Int:iLocation = PlayerGetInfo( iPlayer, PINFO_TRAVEL_TO );
		new String:szLocation[ NAME_LEN ];
		LocationToName( iLocation, szLocation, charsmax(szLocation) );

		player_set_data( iPlayer, "PokeMod", "Location", szLocation );
		PlayerSetInfo( iPlayer, PINFO_LOCATION, iLocation );
		PlayerSetInfo( iPlayer, PINFO_TRAVELING, 0 );
		PlayerSetInfo( iPlayer, PINFO_TRAVEL_TIME, 0 );

		DHudEventMessage( iPlayer, "You are now at %s.", szLocation );

		MenuMain( iPlayer, .bForceDisplay = true );
	}

	pokemod_funcend_debug( "LocationUpdate" );
}

PM_FUNC_NORM_ATTRIB LocationSet( Int:iPlayer, Int:iLocation )
{
	pokemod_funcstart_debug( "LocationSet" );

	new String:szLocation[ NAME_LEN ];
	LocationToName( iLocation, szLocation, charsmax(szLocation) );

	player_set_data( iPlayer, "PokeMod", "Location", szLocation );
	PlayerSetInfo( iPlayer, PINFO_LOCATION, iLocation );
	PlayerSetInfo( iPlayer, PINFO_TRAVELING, 0 );
	PlayerSetInfo( iPlayer, PINFO_TRAVEL_TIME, 0 );

	pokemod_funcend_debug( "LocationSet" );
}

PM_FUNC_NORM_ATTRIB LocationScript( Int:iPlayer, Int:iLocation, String:szForward[], String:szArgument[] = "" )
{
	pokemod_funcstart_debug( "LocationScript" );

	new Int:iTell, Int:iAssumedTell;

	if ( g_iLocationGlobal > -1 )
	{
		iAssumedTell = ArrayGetCell( g_iLocationTells, g_iLocationGlobal );
		FileScript( iPlayer, FileName( FILE_LOCATIONS ), "Global", szForward, szArgument, iAssumedTell, iTell );
		if ( iAssumedTell != iTell )
			ArraySetCell( g_iLocationTells, g_iLocationGlobal, iTell );
	}

	iAssumedTell = ArrayGetCell( g_iLocationTells, iLocation );
	FileScript( iPlayer, FileName( FILE_LOCATIONS ), LocationToName( iLocation ), szForward, szArgument, iAssumedTell, iTell );
	if ( iAssumedTell != iTell )
		ArraySetCell( g_iLocationTells, iLocation, iTell );

	pokemod_funcend_debug( "LocationScript" );
}

